<template>
  <div class="chat-settings-container">
    <div class="settings-header">
      <div class="back-button" @click="goBack">
        <span>&lt;</span>
      </div>
      <span>聊天设置</span>
    </div>
    
    <div class="settings-content">
      <div class="settings-section">
        <h3>通知设置</h3>
        <div class="settings-item">
          <span>消息通知</span>
          <label class="switch">
            <input type="checkbox" v-model="settings.notifications">
            <span class="slider"></span>
          </label>
        </div>
        <div class="settings-item">
          <span>声音提醒</span>
          <label class="switch">
            <input type="checkbox" v-model="settings.sound">
            <span class="slider"></span>
          </label>
        </div>
      </div>
      
      <div class="settings-section">
        <h3>聊天记录</h3>
        <div class="settings-item button" @click="clearHistory">
          <span>清空聊天记录</span>
          <span class="arrow">&gt;</span>
        </div>
      </div>
      
      <div class="settings-section">
        <h3>隐私设置</h3>
        <div class="settings-item">
          <span>在线状态显示</span>
          <label class="switch">
            <input type="checkbox" v-model="settings.showOnlineStatus">
            <span class="slider"></span>
          </label>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter();

// 设置项
const settings = ref({
  notifications: true,
  sound: true,
  showOnlineStatus: true
});

// 返回上一页
function goBack() {
  router.back();
}

// 清空聊天记录
function clearHistory() {
  if (confirm('确定要清空所有聊天记录吗？此操作不可恢复。')) {
    // 清空本地存储的聊天记录
    try {
      localStorage.removeItem('chat_history');
      alert('聊天记录已清空');
    } catch (error) {
      console.error('清空聊天记录失败:', error);
      alert('清空聊天记录失败');
    }
  }
}
</script>

<style scoped>
.chat-settings-container {
  height: 100vh;
  width: 100%;
  display: flex;
  flex-direction: column;
  background-color: #f5f5f5;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
}

.settings-header {
  padding: 15px;
  background-color: #ececec;
  border-bottom: 1px solid #ddd;
  font-weight: bold;
  text-align: center;
  position: relative;
}

.back-button {
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
}

.settings-content {
  flex: 1;
  padding: 15px;
  overflow-y: auto;
}

.settings-section {
  background-color: white;
  border-radius: 8px;
  margin-bottom: 20px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.settings-section h3 {
  padding: 10px 15px;
  margin: 0;
  font-size: 14px;
  color: #999;
  background-color: #f9f9f9;
}

.settings-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px;
  border-bottom: 1px solid #eee;
}

.settings-item:last-child {
  border-bottom: none;
}

.settings-item.button {
  cursor: pointer;
}

.settings-item.button:active {
  background-color: #f0f0f0;
}

.arrow {
  color: #ccc;
}

/* 开关样式 */
.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: .4s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: #07C160;
}

input:checked + .slider:before {
  transform: translateX(26px);
}
</style> 